home *** CD-ROM | disk | FTP | other *** search
- Path: leland.Stanford.EDU!kurri
- From: kurri@leland.Stanford.EDU (Ramana Reddy Kurri)
- Newsgroups: comp.lang.c++
- Subject: Re: How to delete array of pointers?
- Date: 12 Feb 1996 04:09:27 GMT
- Organization: Stanford University
- Message-ID: <4fmehn$cum@nntp.Stanford.EDU>
- References: <4fgvsu$5q4@eng_ser1.erg.cuhk.hk>
- NNTP-Posting-Host: amy6.stanford.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Marty McFly (ywleung@cs.cuhk.hk) wrote:
- : If I write the following code in a function:
-
- : int** ptr;
- : ptr = new int*[1000];
-
- : Is this code means allocating 1000 integer pointers which is pointed by ptr?
-
- YES
-
- : And then somehow I assign integer variable to ptr[0], ptr[1], ... and so on.
-
- for(int i=0; i<1000; i++)
- ptr[i] = new int(value); //value is whatever int value you want
-
- : So at the end of the function, how can I reclaim just those pointers? The key
- : point is that those integer variable assigned to the pointers should not be
- : deleted.
-
- You cannot keep the values pointed by ptr[0], ptr[1], ptr[2] etc.... after deleting
- the memory to them.
-
-
- : Regards,
- : Marty McFly.
-
- Ramana
-